﻿<Window x:Class="WindowsUpdateNotifier.SettingsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:p="clr-namespace:WindowsUpdateNotifier.Resources"
        xmlns:app="clr-namespace:WindowsUpdateNotifier"
        Title="{x:Static p:TextResources.WindowTitle_Settings}" ResizeMode="NoResize" SizeToContent="WidthAndHeight" MinWidth="400"
        Icon="/WindowsUpdateNotifier;component/Resources\Images\WindowsUpdate.ico"
        WindowStartupLocation="CenterScreen" WindowStyle="SingleBorderWindow">

    <Window.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="SaveButtonStyle" TargetType="{x:Type Button}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=RefreshInterval, Path=(Validation.HasError)}" Value="True">
                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding ElementName=AdditionalKbIds, Path=(Validation.HasError)}" Value="True">
                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type CheckBox}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="#FF848484" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="#FF848484"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <BooleanToVisibilityConverter x:Key="BooleanConverter" />
    </Window.Resources>
    
    <Window.DataContext>
        <app:SettingsViewModel CanNotInstallUpdates="True" CanInstallUpdates="False" Version="Version 9.9.9.9  © Christoph Pangerl"
                                                 SaveFailed="True" AutoInstallComment="This feature automatically downloads and installs the updates for the Windows Defender (updates for KB{0}). No other update will be affected by enabling this feature."/>
    </Window.DataContext>
    
    <DockPanel x:Name="MainContent">
        
        <Popup IsOpen="{Binding SaveFailed}"
            PlacementTarget="{Binding ElementName=MainContent}"
            Placement="Relative" 
            AllowsTransparency="True"
            PopupAnimation="Fade"
            HorizontalOffset="140">

            <Border Canvas.Left="200" Background="{StaticResource ErrorColor}" CornerRadius="0,0,5,5">
                <TextBlock Text="{x:Static p:TextResources.Label_SavingSettingsFailed}" Margin="5,2"
                           Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Border>
        </Popup>

        <Border 
            x:Name="BottomArea" 
            DockPanel.Dock="Bottom" 
            VerticalAlignment="Bottom" 
            Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" 
            BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" 
            BorderThickness="0,1,0,0">

            <DockPanel LastChildFill="False">
                <Button x:Name="CancelButton" Content="{x:Static p:TextResources.Button_Cancel}" DockPanel.Dock="Right" IsCancel="True" 
                    Margin="0,5,10,5" MinWidth="75" MinHeight="25" Padding="5,2"/>

                <Button x:Name="SaveButton" Content="{x:Static p:TextResources.Button_Ok}" DockPanel.Dock="Right"
                    Margin="0,5,10,5" MinWidth="75" MinHeight="25" Padding="5,2" 
                    Command="{Binding SaveAndCloseCommand}" Style="{StaticResource SaveButtonStyle}"/>

                <Image Source="/WindowsUpdateNotifier;component/Resources/Images/Help.png" 
                       Width="20" Height="20" Margin="10,0,0,0" DockPanel.Dock="Left" x:Name="HelpIcon"/>

                <TextBlock Margin="5, 10" HorizontalAlignment="Center" ToolTip="{Binding HelpLink}">
                    <Hyperlink Command="{Binding ShowHelpCommand}">
                        <TextBlock Text="{x:Static p:TextResources.Label_Help}"/>
                    </Hyperlink>
                </TextBlock>

                <Popup IsOpen="{Binding ElementName=HelpIcon,Path=IsMouseOver, Mode=OneWay}"
                       PlacementTarget="{Binding ElementName=HelpIcon}"
                       Placement="Relative"
                       AllowsTransparency="True"
                       PopupAnimation="Fade"
                       HorizontalOffset="80"
                       VerticalOffset="1">

                    <TextBlock Text="{Binding Version}" Margin="25, 10, 0, 0" Foreground="#919191" />
                </Popup>
            </DockPanel>
        </Border>

        <GroupBox Margin="10" Header="{x:Static p:TextResources.Label_CommonSettings}" DockPanel.Dock="Top">
            <StackPanel VerticalAlignment="Top" Margin="10,20,10,10">
                <CheckBox Content="{x:Static p:TextResources.Label_SetAsAutoStartup}" x:Name="check"
                          IsChecked="{Binding IsSetAsAutoStartup}" UseLayoutRounding="False" Margin="0,0,0,10"/>
                
                <CheckBox Content="{x:Static p:TextResources.Label_HideIcon}" 
                          IsChecked="{Binding HideIcon}" UseLayoutRounding="False" Margin="0,0,0,10"/>

                <CheckBox Content="{x:Static p:TextResources.Label_DisableNotifications}" 
                          ToolTip="{x:Static p:TextResources.ToolTip_DisableNotifications}" 
                          IsChecked="{Binding DisableNotifications}" UseLayoutRounding="False" Margin="0,0,0,10"/>

                <CheckBox Content="{x:Static p:TextResources.Label_UseMetroStyleForPopup}" 
                          ToolTip="{x:Static p:TextResources.ToolTip_UseMetroStyleForPopup}" 
                          IsChecked="{Binding UseMetroStyle}" UseLayoutRounding="False" Margin="0,0,0,10"/>
                
                <DockPanel Margin="0,10,0,0">
                    <TextBlock Text="{x:Static p:TextResources.Label_RefreshInterval}"/>
                    <TextBox Name="RefreshInterval" Text="{Binding RefreshInterval, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Width="40" Margin="10,0,0,0" HorizontalContentAlignment="Right" />
                    <TextBlock Text="{x:Static p:TextResources.Label_Minutes}" Margin="10,0,0,0"/>
                </DockPanel>
            </StackPanel>
        </GroupBox>

        <GroupBox Margin="10,0,10,10" Header="{x:Static p:TextResources.Label_AutoInstallSettings}" DockPanel.Dock="Top">
            <StackPanel VerticalAlignment="Top" Margin="10,10,10,10">
                <DockPanel Margin="0,0,0,10" Visibility="{Binding CanNotInstallUpdates, Converter={StaticResource BooleanConverter}}">
                    
                    <Image Source="/WindowsUpdateNotifier;component/Resources/Images/warning.png" 
                        Width="20" Height="20" Margin="5,5,15,0" VerticalAlignment="Top"
                        DockPanel.Dock="Left"/>

                    <StackPanel>
                        <TextBlock MaxWidth="410" TextWrapping="WrapWithOverflow" TextAlignment="Justify"
                            Text="{x:Static p:TextResources.Label_AutoInstallNotAvailable}" />

                        <TextBlock MaxWidth="410" ToolTip="{Binding HowToStartAsAdminLink}" Margin="0,10,0,0">
                            <Hyperlink Command="{Binding ShowHowToStartAsAdminCommand}">
                                <TextBlock Text="{x:Static p:TextResources.Label_HowToStartAsAdmin}"/>
                            </Hyperlink>
                        </TextBlock>
                    </StackPanel>

                </DockPanel>
                
                <CheckBox Content="{x:Static p:TextResources.Label_AutoInstallWindowsDefenderUpdates}" 
                    UseLayoutRounding="False" Margin="0,10,0,10"
                    IsChecked="{Binding InstallUpdates}" 
                    IsEnabled="{Binding CanInstallUpdates}" />

                <TextBlock MaxWidth="418" TextWrapping="WrapWithOverflow" Margin="21,0,0,0" TextAlignment="Justify"
                    IsEnabled="{Binding CanInstallUpdates}" HorizontalAlignment="Left"
                    Text="{Binding AutoInstallComment}" />

                <TextBlock Text="{x:Static p:TextResources.Label_AdditionalKbIdsToInstall}" 
                	UseLayoutRounding="False" Margin="20,20,0,10" 
                    MaxWidth="418" TextAlignment="Justify" TextWrapping="WrapWithOverflow" 
                	IsEnabled="{Binding CanInstallUpdates}" />

                <TextBox Name="AdditionalKbIds" IsEnabled="{Binding CanInstallUpdates}" UseLayoutRounding="False" Margin="20,0,0,0"
                         Text="{Binding AdditionalKbIds, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
            </StackPanel>
        </GroupBox>
    </DockPanel>
</Window>
